package com.example.demo.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.example.demo.auth.entity.UpUnit;
import com.example.demo.auth.entity.UpUnitExt;
import com.example.demo.auth.service.UpUnitService;


@Service("upUnitService")
public class UpUnitServiceImpl implements UpUnitService {
	@Autowired
    private JdbcTemplate jdbcTemplate;

    public UpUnit getUnit(Long nid) {
    	UpUnit upUnit;
    	String sql = "SELECT UT.NID, UT.NPID, UT.ID, UT.NAME, UT.DESCRIPTION, UT.CODE, UT.TYPE_ID,\n" + 
        		"       UT.IS_ENABLED, UT.ACTIVE_FLAG, UT.CREATED_BY, UT.CREATION_DATE,\n" + 
        		"       UT.LAST_UPDATED_BY, UT.LAST_UPDATE_DATE, UT.DELETION_DATE, UE.BAE043 PARENT_UNIT_ID\n" + 
        		"  FROM V_IDM_UNIT UT, V_IDM_UNIT_USER UU, V_IDM_USER US\n" + 
        		" WHERE UT.IS_ENABLED = 'T' AND UT.ACTIVE_FLAG = 'T' AND UU.ACTIVE_FLAG = 'T'\n" + 
        		"   AND US.ACTIVE_FLAG = 'T' AND UT.NID = UU.NUNITID AND US.NID = UU.NUSERID\n" + 
        		"   AND US.NID = ?";
        upUnit =  jdbcTemplate.queryForObject(sql.toString(), UpUnit.class,nid);
        return upUnit;
    }


	public UpUnitExt getUnitExt(Long nid) {
		UpUnitExt upUnitExt;
        String sql = "SELECT UE.NID, UE.ID, UE.AAB301, UE.AAB302\n" + 
        		"  FROM V_ORG_UNIT_EXT UE, V_IDM_UNIT U\n" + 
        		" WHERE UE.NID = U.NID AND U.NID = ? ";
        upUnitExt =  jdbcTemplate.queryForObject(sql.toString(), UpUnitExt.class,nid);
        return upUnitExt;
	}

}
